/**
 * shell.h
 *
 *  Created on: 2016-11-23
 *      Author: chenshisheng
 */

#ifndef MAIN_SHELL_H_
#define MAIN_SHELL_H_

#include "main.h"
#include "stream/stream.h"

#include <stdlib.h>

BEGIN_C_DECLS
#define shell_declare(name) \
    static const Shell_Cmd_t _shell_cmd_##name \
    __attribute__((used, unused, section(".shell_cmds." #name)))

#define SHELL_CMD(name, cmd, brief, usage) \
    shell_declare(name) = {#name, cmd, brief, usage}


typedef int (* Shell_Callback_t)(void *stream, int argc, char *argv[]);

typedef struct
{
    const char *name;
    Shell_Callback_t callback;
    const char *brief;
    const char *usage;
}Shell_Cmd_t;

void Shell_Init(void);
int Shell_SendLineSignal(const Stream_LineSignal_t *sig);
int Shell_RecvOSLineSignal(Stream_LineSignal_t *sig);
void Shell_OnLine(Stream_LineSignal_t *sig);
void Shell_Help(void *stream, const char *cmdName);

END_C_DECLS
#endif /* MAIN_SHELL_H_ */
